package com.example.student.controller;

import com.example.student.utils.ResponseResult;
import com.wf.captcha.SpecCaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.concurrent.TimeUnit;
import java.util.HashMap;
import java.util.Map;

/**
 *  设置验证码数据
 * */
@RestController
public class SetCode{
    /**
     *  设置验证码数据
     * */
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @GetMapping("/code")
    public ResponseResult code(){

        SpecCaptcha specCaptcha = new SpecCaptcha(125,48,5);
        // 生成的code
        String code = specCaptcha.text();
        // Base64编码
        String codeBase64 = specCaptcha.toBase64();
        redisTemplate.opsForValue().set("code",code.toUpperCase(),60,TimeUnit.SECONDS);
        return ResponseResult.success("成功", codeBase64);
    }
}